package util;

public class GameClock {
	static long currentTime;
	private static long pauseTime;
	private static long totalPausedTime;
	long tick;
	
	private boolean isPaused;
	
	public GameClock(){
		currentTime = System.currentTimeMillis();
	}

	private static class GameClockHolder {
		public static final GameClock instance = new GameClock();
	}

	public static GameClock getInstance(){
		return GameClockHolder.instance;
	}
	
	public void tick(){
		if(!isPaused){
			tick = System.currentTimeMillis() - currentTime - totalPausedTime;
			currentTime += tick;
		}
	}

	/**
	 * 
	 * @return The time OF the last tick.
	 */
	public long getCurrentTime(){ return currentTime; }
	/**
	 * 
	 * @return The time SINCE the last tick.
	 */
	public long getTick(){ if(isPaused) return 0; return tick; }
	
	public void pause(){
		if(!isPaused){
			Logger.log("Paused");
			pauseTime = System.currentTimeMillis();
			isPaused = true;
		}
	}
	
	public void resume(){
		if(isPaused){
			Logger.log("Resumed");
			totalPausedTime += System.currentTimeMillis() - pauseTime;
			isPaused = false;
		}
	}
}
